<template>
  <div class="iptwrapper">
    <div class="disable" v-if="!isShowTextarea">
      <input type="text" class="ipt" @focus="showText" :value="content" />
      <div class="contentnum">
        <span class="iconfont iconpinglun-"></span>
        <div class="num">1020</div>
      </div>
      <span class="iconfont iconshoucang"></span>
      <span class="iconfont iconfenxiang"></span>
    </div>

    <div class="enable" v-if='isShowTextarea'>
      <textarea v-model="content" ref="textarea" rows="3" @blur="hideTextarea"></textarea>
      <div class="sendBtn" @click="send">发送</div>
    </div>
  </div>
</template>

<script>
import Bus from '../../utis/bus'
export default {
    data(){
        return{
            isShowTextarea:false,
            content:'',
            parent_id:''
        }
    },
    created(){
      Bus.$on('callRly',(id)=>{
          console.log('我要回复的id',id);
          this.parent_id=id
          this.showText()
      })
    },
  methods:{
      showText(){
          this.isShowTextarea = true;
           this.$nextTick(()=>{
                this.$refs.textarea.focus()
            })
        },
     hideTextarea(){     
         this.parent_id = ''
        setTimeout(()=>{
             this.isShowTextarea = false;
        },1000)
     },
     send(){
         if(!this.content){
             return 
         }
        //  console.log(this.content);
        //  console.log(this.$route.query.id);
         this.$axios({      
             url:'/post_comment/'+ this.$route.query.id,
             method:'post',
             data:{
             content:this.content,
             parent_id:this.parent_id 
             }
         }).then((res)=>{
             console.log(res);
             this.content='';
             this.$emit('reloadComment')
         })
     }


 }
  }

</script>
<style lang="less">
.iptwrapper {
  position: fixed;
  bottom: 0;
  left: 0;
  background: #e4e4e4;
  width: 100%;
  .disable {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10/360 * 100vw;
    .ipt {
      width: 181/360 * 100vw;
      height: 30/360 * 100vw;
      line-height: 30/360 * 100vw;
      background-color: #cccccc;
      padding-left:20/360*100vw ;
      border: none;
      outline: none;
      border-radius: 16/360 * 100vw;
    }
    .iconfont {
      font-size: 24/360 * 100vw;
    }
    .contentnum {
      position: relative;
      .num {
        position: absolute;
        top: -4px;
        left: 5px;
        padding: 2px;
        font-size: 12px;
        background-color: #ff0000;
        border-radius: 24px;
        color: #ffffff;
      }
    }
  }
  .enable {
        display: flex;
        align-items: flex-end;
        padding: 10/360*100vw;
        textarea {
            flex: 1;
            padding: 14/360*100vw;
            border-radius: 14/360*100vw;
            background-color: #ccc;
            border: none;
            outline: none;
        }
        .sendBtn {
            background-color: red;
            color: #fff;
            font-size: 14/360*100vw;
            line-height: 22/360*100vw;
            padding: 0 14/360*100vw;
            border-radius: 12/360*100vw;
            margin-left: 10/360*100vw;
        }
    }
}
</style>